from django.contrib.auth import get_user_model
from django.db import models

from questions.models import Question

User = get_user_model()


class AuestionPicture(models.Model):
    image = models.CharField(max_length=300, blank=True, null=True)


class Answer(models.Model):
    content = models.TextField(blank=True)
    praise = models.IntegerField(default=0)
    pictures = models.ManyToManyField(AuestionPicture)
    creator = models.ForeignKey(User, related_name='answers', on_delete=models.CASCADE)
    question = models.ForeignKey(Question, related_name='answers', on_delete=models.CASCADE)

    created_time = models.DateTimeField(auto_now_add=True)


class AnswerPraiseRelationship(models.Model):
    answer = models.ForeignKey(Answer, related_name='apr', on_delete=models.CASCADE)
    user = models.ForeignKey(User, related_name='apr', on_delete=models.CASCADE)

    praise = models.BooleanField(default=False)

    created_time = models.DateTimeField(auto_now_add=True)


class AnswerFocus(models.Model):
    """关注收藏"""
    answer = models.ForeignKey(Answer, related_name='answerfocus', on_delete=models.CASCADE)
    creator = models.ForeignKey(User, related_name='answerfocus', on_delete=models.CASCADE)
    created_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        unique_together = (("creator", "answer"),)
